<?
	class siteCheckr
	{
		var $link_names;		//names, indexed by URL
    	var $link_urls;			//urls, indexed by name
    	var $visited_links;		//urls visited
    	var $to_visit;			//urls to visit
    	var $broken;			//broken urls
    	var $other_servers;		//other servers to parse
    	var $ignore;			//keywords to ignore
    	var $cache;				//a cache of the HTML content of all pages, indexed by url
    	
    	var $catalogue;			//a special array used by the Catalogue Site action
    	var $cataloguePages;	//an array of valid pages to visit to generate a summary (basically the index pages for each section)
    	
    	var $actions;			//index of actions; stores corresponding function (to eval) as well as summary function (to eval)
    	
    	var $validatorURL;		//direct link to the HTML validator
    	   	
    	function siteCheckr(){
    		/**
    		 * Default constructor
    		 * 
    		 */
    		
    		$this->link_names    = array();
    		$this->link_urls     = array();
    		$this->misc          = array(); //miscellaenous use by actions
    		$this->visited_urls  = array();
    		$this->to_visit      = array();
    		$this->broken        = array();
    		$this->other_servers = array(); 
    		$this->ignore        = array();
    		$this->cache         = array();//[iHtmlText]
    		
    		$this->catalogue     = array();//used specifically by the 'Catalogue Site' option
    		$this->cataloguePages = array();
    		$this->catalogue_sup = array();//catalogue supplement; contains links from the main page; should only be used by 'Catalogue Site'
    		
    		//arrays for domain_catalogue
    		$this->unique_domains = array();			//list of all the unique names; includes a list of numbers referencing URLs which contain links to domain
    		$this->url_keys       = array();			//an array indexed by URL; contains keys to URLs
    		$this->key_urls		  = array();			//array indexed by key; used to look up URLs
    		
    		//arrays for sitemap
    		$this->name_url_pair  = array();
    		
    		$this->debug = 0;			//0 = debug off; 1 = debug on
    				
    		//if pages are added or changed, make changes here
    		//I believe this stuff is needed to correctly do the site catalogue
    		$this->cataloguePages["http://iet.ucdavis.edu/rooms/"]["valid"]      = 1;
    		$this->cataloguePages["http://iet.ucdavis.edu/admin"]["valid"] 		= 1;
    		$this->cataloguePages["http://security.ucdavis.edu/"]  ["valid"]     = 1;
    		$this->cataloguePages["http://iet.ucdavis.edu/teaching/"] ["valid"]   = 1;
    		$this->cataloguePages["http://iet.ucdavis.edu/computing/"]["valid"]   = 1;
    		$this->cataloguePages["http://iet.ucdavis.edu/help/"]["valid"]        = 1;
    		$this->cataloguePages["http://iet.ucdavis.edu/telecom/"]["valid"]     = 1;
    		
    		$this->cataloguePages["Classrooms &amp; Computer Rooms"]["url"] 	     	= "http://iet.ucdavis.edu/rooms";
    		$this->cataloguePages["Administrative Systems"]["url"] 		= "http://iet.ucdavis.edu/admin";
    		$this->cataloguePages["Computer Security"]["url"] 		= "http://security.ucdavis.edu/";
    		$this->cataloguePages["Educational Technology"]["url"] 		= "http://iet.ucdavis.edu/teaching";
    		$this->cataloguePages["Email &amp; Computing Services"]["url"]		= "http://iet.ucdavis.edu/computing";
    		$this->cataloguePages["Help &amp; Training"]["url"] 			= "http://iet.ucdavis.edu/help";
    		$this->cataloguePages["Network &amp; Telecom Services"]["url"] 		= "http://iet.ucdavis.edu/telecom";
    
    		//these are needed to pull the information from the divs on the main page, for the catalogue    		
    		$this->divNames["bottom_middle"] = "How do I... ?";
    		$this->divNames["midnav"]        = "IET Departments";
    		$this->divNames["toprightnav"]   = "Navigation";
    		$this->divNames["topnav"]        = "Audience";
    		$this->divNames["left"]          = "Quick Links";
    		
    		//specifies the URL to the validator (on skycar)
    		$this->validatorURL = "http://skycar.ucdavis.edu/validator/validator-0.7.2/htdocs/check.cgi?uri=";
    	}
    	
    	function registerAction($action, $function, $summary){
    		/**
    		 * 'Registers' an action with the Checker
    		 * Allows the lookup of an action, to determine what function to run, and which summary to display
    		 * 
    		 * @param string $action The name of the action to index
    		 * @param string $function The function to be done on each page (eval)
    		 * @param string $summary The function to be done at the end of the processing (eval)
    		 * @return void
    		 */
    		
    		$this->actions[$action]["function"] = $function;
    		$this->actions[$action]["summary"]  = $summary;
    	}
    	
    	function getFunction($action){
    		/**
    		 * Returns the function associated with the action
    		 * 
    		 * @param string $action The name of the action to lookup
    		 * @return string The code associated with the function to be used with eval
    		 */
    		
    		return $this->actions[$action]["function"];
    	}
    	
    	function getSummary($action){
    		/**
    		 * Returns the summary function associated with the action
    		 * 
    		 * @param string $action The name of the action to lookup
    		 * @return string The code associated with the summary function to be used with eval
    		 */
    		
    		return $this->actions[$action]["summary"];
    	}
    	
    	function spin($parser, $nodeType, $nodeName = null){
    		/**
    		 * 'Spins' the parser until it reaches the specified node-type
    		 * For instance, you might 'spin', ignoring all test, until you reach an anchor <a> tag
    		 * Specifying a node name is optional
    		 * 
    		 * @param parser  $parser   Reference to the parser we're currently working with
    		 * @param integer $nodeType Type of $parser node we're looking for
    		 * @param string  $nodeName Name of the node we're looking for (optional)
    		 * @return parser
    		 */
    		
    		while($parser->iNodeType != $nodeType and ($nodeName == null or $parser->iNodeName = $nodeName)){

    			$parser->parse();
    		}	
    		
    		return $parser;
    	}
    	
    	function handleLink($parser, $main_url){
    		/**
    		 * Checks to see if node is an anchor (<a>).  If it is, generate the 'correct' URL for it.
    		 * Attempt to add the URL to the list of nodes to visit.  Returns the URL generated
    		 * 
    		 * @param parser $parser The parser object to use
    		 * @param string $main_url The URL of the page currently being parsed
    		 * @return string The 'modified' URL
    		 * 
    		 */
	
    		if ($parser->iNodeType == NODE_TYPE_ELEMENT and strtolower($parser->iNodeName) == "a") {      		
	        	 $url = $parser->iNodeAttributes["href"];	              

	        	 $url = linkResolver($main_url, $url);
	   	             
	                //add the link to the 'to visit' list IF it's on the same domain (or in list of domains) and is not a PDF (or other file type TODO)
	                //also anchors are causing headaches so just don't visit them.  EVER
	                //UPDATE: LOL the above comment is too funny to remove, but we need to visit anchors... we'll try exploding the $url and just not taking the # part if it's there
	                if(strstr($url, "#")){
	                	$url = explode("#", $url);
	                	$url = $url[0];
	                	echo "$url<br>";
	                }
	                
	                if(!isset($this->visited_links[$url]) and strstr($this->other_servers, getHost($url)) and !strstr($url, ".pdf")  and !strstr($url, '@')){
	                	$this->to_visit[$url] = 1;
	                }
	                	
	        } //end if anchor

	        return $url;
    	}
    	
    	function processList($parser, $divID){
    		/**
    		 * Processes a <ul> node, grabbing text from each <li> tag and inserting it into an array; returns the array
    		 * @param parser $parser Reference to the parser we're using currently
    		 * @return array
    		 */
    		
    		$links = 0;		//count the number of links
    		
    		//echo"Entering process list; currently at " . $parser->iNodeName . "<br>";
    		if($parser->iNodeType == NODE_TYPE_ELEMENT and strtolower($parser->iNodeName) == "ul"){
    			while($parser->iNodeType != NODE_TYPE_ENDELEMENT or $parser->iNodeName != "ul"){
	    			while($parser->iNodeName != "li")
		        				$parser->parse();
	    			//if($parser->iNodeType == NODE_TYPE_ELEMENT and strtolower($parser->iNodeName) == "li"){
						while($parser->iNodeName != "a")
		        				$parser->parse();
	 	  				if($parser->iNodeType == NODE_TYPE_ELEMENT and strtolower($parser->iNodeName) == "a"){
	 	  					$url = $parser->iNodeAttributes["href"];
	 	  					$parser->parse();
	 	  					if($parser->iNodeType == NODE_TYPE_TEXT){
				                	$text = '';
			
				                	while($parser->iNodeType != NODE_TYPE_ENDELEMENT){
				                		$text .= $parser->iNodeValue . ' ';
				                		$parser->parse();
			                		}              		
			                		
			                		$this->catalogue_sup[$divID . $links]['title'] = $text;
			                		$this->catalogue_sup[$divID . $links]['dept']  = $divID;
			                		$this->catalogue_sup[$divID . $links]['url']   = $url;
			                		$links++;
			                		
			                		$this->debug($text . "<br>");

			                		// "Discarding " . $parser->iNodeName . "<br>";
			                		$parser->parse(); //discard </a>
			                		
			                		//spin until we get an li
			                		while($parser->iNodeName != "li"){
			                			//echo "Discarding " . $parser->iNodeName . "<br>";
			                			$parser->parse();
			                		}
			                		
			                		$parser->parse();
			                		
			                		//echo "Entering spin cycle on " . $parser->iNodeName . "<br>";
			                		
			                		while($parser->iNodeType != NODE_TYPE_ENDELEMENT and !($parser->iNodeName == "ul" or $parser->iNodeName == "li")){
			                			//echo "spinning<br>";
			                			$parser->parse();
			                		}
			                		
			                		//echo "Ending current cycle with " . $parser->iNodeName . "<br>";
			                		
			                		if($parser->iNodeName == "ul"){
			                			//echo "LEAVING PROCESS LIST -----------<br>";
			                			return;
			                		}
		                		} // end if text
	 	  				} //end if anchor
	    			} // end if li
    			//} //end while
    		} //end if ul
    		
    		
    	}
    	
    	//the summary function called for the 'header' action
    	function headerSummary(){
    		echo "<table width = '1400' cellpadding = 0 cellspacing = 0 border = 0>";
    		echo "<tr>";
    		foreach($this->link_names as $page){
    		//hide all anchors, don't want them
	    		if(!strstr($page['url'], "#")){
		    		echo "<td width = '500'>";
		    		echo $page['title'];
		    		echo "</td>";
		    		echo "<td width = '500'>";
		    		echo $page['header'];
		    		echo "</td>";
		    		echo "<td width = '80'>";
		    		echo "</td>";
		    		echo "<td width = '320'>";
		    		echo "<a href = '" . $page['url'] . "'>" . $page['url'] . "</a>";
		    		echo"</td>";
		    		echo "</tr>";
    			} // end if not anchor page
    		} // end for each title
    		echo "</table>";
    	}
    	
    	//the action function for the 'header' action
    	function checkHeaderConsistency($parser, $main_url){   	
			/**
			 * Parses pages for <title> and <h1> nodes.
			 * Summary provides a one-to-one relationship between a page's title and their <h1> header.
			 * 
			 * @param parser $parser The parser object to use
			 * @param string $main_url The main url (root) to behin with
			 * @return void
			 * 
			 */

	        $url = $this->handleLink($parser, $main_url);
 			 
	        //check <title> nodes
	        if ($parser->iNodeType == NODE_TYPE_ELEMENT and strtolower($parser->iNodeName) == "title") { 
	        	//previous element was an title; parse the next token and grab the text
	        	
	        		//while($parser->iNodeType != NODE_TYPE_TEXT)
	                	//$parser->parse();
	             		$parser = $this->spin($parser, NODE_TYPE_TEXT);
	                	$text = '';

		               while($parser->iNodeType != NODE_TYPE_ENDELEMENT){
		               		$text .= $parser->iNodeValue . ' ';
		               		$parser->parse();
		               } //end while node is not end element
		                	
		               $length = strlen($text);
		               $text = substr($text, 0, 50);
	                   $text = "(" . $length . ") "  . $text; 
	                   if($length > 50)
		               		$text .= "...";                		
	
		               //flag titles longer than 64 characters
		               if($length > 64)
		               			$text = "<b>" . $text;
		               if($length > 64)
		               		$text .= "</b>";
	                	

	                if(!isset($this->link_names[$main_url]["title"])){
		               	$this->link_names[$main_url]["title"] = $text;
		               	$this->link_names[$main_url]["url"] = $main_url;
					} //end if title is not set
	        } // end if node is a title

	        //check <h1> nodes
	        if ($parser->iNodeType == NODE_TYPE_ELEMENT and strtolower($parser->iNodeName) == "h1") { 
	        	//previous element was an h1; parse the next token and grab the text
	                
	        		$parser = $this->spin($parser, NODE_TYPE_TEXT);
	                
	                if($parser->iNodeType == NODE_TYPE_TEXT){
	                	$text = '';

	                	while($parser->iNodeType != NODE_TYPE_ENDELEMENT){
	                		$text .= $parser->iNodeValue . ' ';
	                		$parser->parse();
	                	}
	                	
	                	$length = strlen($text);
	                	$text = substr($text, 0, 64);
                		$text = "(" . $length . ") "  . $text; 
                		if($length > 64)
                			$text .= "...";                		
	                	
	                } // If node following <h1> is text ...
	                
	                else {
	                	$text =  "Header contains no text";
	                } //else if node is not text... (it might be a link instead of plain text)
	                	
	                if(!isset($this->link_names[$main_url]["header"]))
	                	$this->link_names[$main_url]["header"] = $text;
	        } 
	
    	}
    	
    	//the summary function for the 'catalogue' action
    	function catalogueSummary(){
    		
    		echo count($this->link_names) . " pages found.<br /><br />";
    		echo "This summary has been automatically saved to file.  <a href = './summary.php.txt'>View the file (./summary.php.txt)</a>.<br /><br />";
    		
    		//sort the results
    		foreach(array_keys($this->link_names) as $key){
    			//if we grabbed a space somehow at the start, remove it
    			
    			
    			//FIX ME UPDATE: I don't remember what this is about
    			$tmp = $key;
    			
    			if (ereg('[^A-Za-z0-9]', $key[0])){
    			
    				$key = substr($key, 1);
    				
    			}
    			
    			$temp[$key] = $this->link_names[$tmp];
    			
    		}

    			ksort($temp);

    		$this->link_names = $temp;
    		print_r($this->link_names);
    		//save this to disk as well //////////////////////////
    		$fd = fopen("./summary.php.txt", "w");
    		if(!$fd)
				echo "Could not open file for writing";
				
			if($fd){
				fwrite($fd, '			
					
						<?php
						include("http://ietincl.ucdavis.edu/includes/head.htm");
						?>
						<title>IET : IET Services at a Glance</title>
						
						</head>
						<body> 
						<div id="page_content">
						<?php
						include("http://ietincl.ucdavis.edu/includes/navbar.htm");
						?>
						<div id="main"> 
						  <div id="main_wrapper"> 
						    <div id="breadcrumb"> <a href="/">IET Home</a>: IET Services at a Glance</div> 
						    <!-- end breadcrumb --> 
						    <h1>IET Services at a Glance</h1>
								<div id="columnwrap">
								<div id="columna" class="content_even">
								

								');
				
					
								fwrite($fd, '<h1>Site Map</h1>');
								fwrite($fd, "<dl>");
				
									$i = 0;
									foreach($this->catalogue as $page){
										$temp_catalogue[$page["dept"] . $i]["title"] = $page['title'];
										$temp_catalogue[$page["dept"] . $i]["url"]   = $page['url'];
										$temp_catalogue[$page["dept"] . $i]["dept"]  = $page['dept'];
										$i++;
									}
									
															
									@ksort($temp_catalogue);
									
									$this->catalogue = $temp_catalogue;
									
									foreach($this->catalogue_sup as $page){
										if(!isset($curDept)){
											$curDept = $page['dept'];
											fwrite($fd, sprintf("<dt><br />%s</dt>", $this->divNames[$curDept]));	
										}
										else if ($curDept != $page['dept']){
											$curDept = $page['dept'];
											fwrite($fd, sprintf("<dt><br />%s</dt>", $this->divNames[$curDept]));	
										}
	
										fwrite($fd, sprintf("<dd><a href = '%s'>%s</a></dd>", $page['url'], $page['title']));									
									}
									
									
									fwrite($fd, "</dl><br /><h1>By Service Area</h1><dl>");

										foreach($this->catalogue as $page){
											if(!isset($curDept)){
												$curDept = $page['dept'];
												fwrite($fd, sprintf("<dt><br />%s</dt>", $curDept));	
											}
											else if ($curDept != $page['dept']){
												$curDept = $page['dept'];
												fwrite($fd, sprintf("<dt><br /><a href = '%s'>%s</a></dt>", $this->cataloguePages[$curDept]["url"],$curDept));	
											}
		
											fwrite($fd, sprintf("<dd><a href = '%s'>%s</a></dd>", $page['url'], $page['title']));									
										}

								fwrite($fd, "</dl>");
				
			
				    			fwrite($fd, '
								
								</div><!-- End columna -->
								<div id="columnb" class="content_even">
								
								<h1>Site Index</h1>
								<div class="section_nav">
								<h1>Quick Links</h1>
								<dl>
									<dt>
										&nbsp;A-E | <a href = "#e">F-J</a> | <a href = "#i">K-O</a> | <a href = "#p">P-T</a> | <a href = "#t">U-Z</a>
									</dt>
								</dl>
								
								</div><!-- End section_nav -->
		
				');
			}
			
			$curLetter = 'a';

	    		foreach($this->link_names as $page){
	
			    	if($page['header'] != ""){
			    		//if this is a transition between letters, add an extra line
			    		if(strtolower($page['header'][0]) != $curLetter){
			    			fwrite($fd, "<a name = '$curLetter'></a><br />");
			    			$curLetter = strtolower($page['header'][0]);
			    			echo "<br />";
			    		}
			    		
			    		$page['header'] = preg_replace("/ $/", "", $page['header']);
			    		
			    		echo "<a href = '" . $page['url'] . "'>" . $page['header'] . " </a><br />";
   
			    		if($fd)
			    			fwrite($fd, sprintf("<a href = '%s'>%s</a><br />\n", $page['url'], $page['header']));	
			    	}
	
	
	    		} // end for each title
		
    		if($fd){
    			fwrite($fd, '
	    			</div><!-- End columnb -->
					</div><!-- End columnwrap -->
						</div><!-- end main_wrapper --> 
					</div>
					<!-- end main --> 
					<?php
					include("http://ietincl.ucdavis.edu/includes/bottomnav.htm");
					?>
					<!-- Footer Bar --> 
					<div id="footer"> Contact: <a href="mailto:ietweb@ucdavis.edu">ietweb@ucdavis.edu</a>     Last modified: October 6, 2006     Copyright Regents of the University of California, 2006 </div> 
					<!-- end footer --> 
					<!-- End Footer Bar -->
					</div>
					</body>
					</html>'

				);
    		}
    		
    		fclose($fd);
    		
    		//print_r($this->catalogue_sup);
    	}
    	
    	//the action function for the 'catalogue' action
    	function catalogueSite($parser, $main_url){   	
			/**
			 * Parses pages for <h1> nodes.
			 * Summary provides a <h1> tag list in alphabetical order
			 * 
			 * @param parser $parser The parser object to use
			 * @param string $main_url The main url (root) to begin with
			 * @return void
			 * 
			 */

	        $url = $this->handleLink($parser, $main_url);
	        
	        if ($parser->iNodeType == NODE_TYPE_ELEMENT and strtolower($parser->iNodeName) == "h1" and !isset($this->link_urls[$main_url])) { 
	        	//previous element was an h1; parse the next token and grab the text
	                //$parser->parse();
	               
	                
	                if(isset($parser->iNodeAttributes["title"])){
	                	$text = $parser->iNodeAttributes["title"];	
	                	echo $text;
	                }                	
	               	else{
	               		 $parser = $this->spin($parser, NODE_TYPE_TEXT);
	               		 
		                if($parser->iNodeType == NODE_TYPE_TEXT){
		                	$text = '';
	
		                	while($parser->iNodeType != NODE_TYPE_ENDELEMENT){
		                		$text .= $parser->iNodeValue . ' ';
		                		$parser->parse();
		                	}              		
		                	
		                } // If node following <h1> is text ...
		                
	               	}
	               	
	               			//special case for titles with quotation marks
	               			$text = str_replace('&quot;', '', $text);
	               			if($text[0] == ' ')
		                		$text = substr($text, 1);
		                	if(!preg_match("/^\w/", $text))
		                		$text = substr($text, 1);
	                
	                if(!isset($this->link_urls[$main_url])){
	                	
	                	if(strstr($text, ";") and !strstr($text, "&amp")){
	                		$t = explode(";", $text);
	                		foreach($t as $multi_title){
	                			$this->link_names[$multi_title]["header"] = $multi_title;
	                			$this->link_names[$multi_title]["url"] = $main_url;
	                		}
	                	}
	                	
	                	else{    
	                		$this->link_names[$text]["header"] = $text;
	                		$this->link_names[$text]["url"] = $main_url;
	                	}
	                	
	                	 	$this->link_urls[$main_url] = 1;
	                	
	                	//echo "$main_url found<br>";
	                	
	                	//determine what section this link is from	                	
	                	if(strpos($main_url, ".ucdavis.edu/admin") > 0)
	                		$this->link_names[$text]["dept"] = "Administrative Systems";
	                	else if(strpos($main_url, ".ucdavis.edu/rooms"))
	                		$this->link_names[$text]["dept"] = "Classrooms &amp; Computer Rooms";
	                	else if(strpos($main_url, "security.ucdavis.edu"))
	                		$this->link_names[$text]["dept"] = "Computer Security";
	                	else if(strpos($main_url, ".ucdavis.edu/teaching"))
	                		$this->link_names[$text]["dept"] = "Educational Technology";
	                	else if(strpos($main_url, ".ucdavis.edu/computing"))
	                		$this->link_names[$text]["dept"] = "Email &amp; Computing Services";
	                	else if(strpos($main_url, ".ucdavis.edu/help"))
	                		$this->link_names[$text]["dept"] = "Help &amp; Training";
	                	else if(strpos($main_url, ".ucdavis.edu/telecom"))
	                		$this->link_names[$text]["dept"] = "Network &amp; Telecom Services";
	                	//else 
            			//	$this->link_names[$text]["dept"] = "Miscellaneous";
            			
	                }
	                
	               
	                return;
	        } 
	        
	        if($this->cataloguePages[$main_url]["valid"] == 1 and $parser->iNodeType == NODE_TYPE_ELEMENT and strtolower($parser->iNodeName) == "dt"){
	        	$parser->parse(); //discard link, for now TODO
	        	
	        	//echo "Parsing DT Page @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<br>";
	        	
	        	if($parser->iNodeType == NODE_TYPE_ELEMENT and strtolower($parser->iNodeName) == "a"){
	        		$current_url = $parser->iNodeAttributes["href"];
	        		
		        	$parser->parse();
		        	
		        	if($parser->iNodeType == NODE_TYPE_TEXT){
		                	$text = '';
	
			            while($parser->iNodeType != NODE_TYPE_ENDELEMENT){
			            	$text .= $parser->iNodeValue . ' ';
			                $parser->parse();
			            }         
			            
			            $this->debug("<br><br>$current_url found with the link text $text<br><br>");
			            
			            if(strpos($main_url, ".ucdavis.edu/admin") > 0)
		                		$this->catalogue[$text]["dept"] = "Administrative Systems";
		                	else if(strpos($main_url, ".ucdavis.edu/rooms"))
		                		$this->catalogue[$text]["dept"] = "Classrooms &amp; Computer Rooms";
		                	else if(strpos($main_url, "security.ucdavis.edu"))
		                		$this->catalogue[$text]["dept"] = "Computer Security";
		                	else if(strpos($main_url, ".ucdavis.edu/teaching"))
		                		$this->catalogue[$text]["dept"] = "Educational Technology";
		                	else if(strpos($main_url, ".ucdavis.edu/computing"))
		                		$this->catalogue[$text]["dept"] = "Email &amp; Computing Services";
		                	else if(strpos($main_url, ".ucdavis.edu/help"))
		                		$this->catalogue[$text]["dept"] = "Help &amp; Training";
		                	else if(strpos($main_url, ".ucdavis.edu/telecom"))
		                		$this->catalogue[$text]["dept"] = "Network &amp; Telecom Services";
		                		
		                		
		                	
		                	$this->catalogue[$text]['title'] = $text;
		                	$this->catalogue[$text]['url']   = linkResolver($main_url, $current_url);
		                    		
		                	
		           } // If node following <dt> is text ...
	
		           //echo $text . " was found<br>";
	        	} // end if anchor
	        }
	        
	        //custom code for main IET page
	        if($main_url == "http://iet.ucdavis.edu" or $main_url == "http://skycar.ucdavis.edu"){
	        	if($parser->iNodeType == NODE_TYPE_ELEMENT and strtolower($parser->iNodeName) == "div"){
	        		$id = $parser->iNodeAttributes["id"];
	        		$this->debug("Div $id found ---------------------------<br>");
	        		//we've gotten the ID of the div; process it based on the ID
	        		if($id == "toprightnav" or $id == "midnav" or $id == "bottom_middle" or $id == "topnav" or $id == "left"){
	        			$this->debug("Processing $id...<br>");
	        			//read the next tag (should be a ul)
	        			while($parser->iNodeName != "ul"){
	        				$parser->parse();
	        				//echo "here";	
	        			}
	        			//echo "Node is currently " . $parser->iNodeName . "<br>";
	        			$this->processList($parser, $id);
	        		}
	        	}
	        }
    	}
    	
    	function HTMLSummary(){		
    		//validate IP address
    		$ip = $_SERVER["REMOTE_ADDR"];

    		exec("mkdir $ip");
    			
    		$fd = fopen("./$ip/batch_html", "w");
    		if(!$fd){
    			echo("Could not open file descriptor for ./$ip/batch.html... aborting");
    			return;
    		}
    		
    		foreach($this->link_names as $link){
    			fwrite($fd, $this->validatorURL . $link['url'] . "\n");
    		}
    		
    		fclose($fd);

    		exec("./validate_html $ip");
    		
    		$fd = fopen("./$ip/output", "r");
    		
    		//start table
    		echo "<table width = 1000>";
    		
    		while(!feof($fd)){
    			$page = fgets($fd);
    			$page = str_replace("check.cgi?uri=", "", $page);
    			$page = str_replace("./$ip/", "", $page);
    			$page = str_replace(".1.html", "", $page);
    			$page = str_replace("%2F", "/", $page);
    			
    			$tokens = explode('@', $page);
    			
    			//determine if the page had errors or not
    			$errors = 0;
    			if(strstr($tokens[1], "Failed")){
    				//determine how many errors there were 
    				$tmp = explode(',', $tokens[1]);
    				$errors = substr($tmp[1], 1);	
    				$tokens[1] = $tmp[0];
    			}
    			
    			//make sure we didn't pick up a blank line
    			if(isset($tokens[0]) or $tokens[0] == "\n" or $tokens[0] == "" or strlen($tokens[0]) < 2){
    				echo "<tr>";
    					echo "<td width = '500'>";
    						echo "<a href = '" . $tokens[0] . "'>" . $tokens[0] . "</a>";
    					echo "</td>";
    					echo "<td width = '200'>";
    						if(!strpos($tokens[1], "valid")){
    							echo "<font color = 'blue'>";
    							echo "Could not auto-validate " . $tokens[1];
    							echo "</font>";
    						}	
    						else if(strstr($tokens[1], "Passed")){
    							echo "<font color = 'green'>";
    							echo $tokens[1];
    							echo "</font>";
    						}
    						else{
    							echo "<font color = 'red'>";
    							echo $tokens[1];
    							echo "</font>";
    						}
    					echo "</td>";
    					echo "<td width = '300'>";
    						$errors = explode(" ", $errors);
    						echo $errors[0];
    					echo "</td>";
    				echo "</tr>";
    			}
    			
    		}
    		
    		echo "</table>";
    		//end table
    		
    		fclose($fd);
    	}
    	
    	function checkValidHTML($parser, $main_url){
 			/**
 			 * On each page, applies: http://skycar.ucdavis.edu?verbose=1&uri=$main_url.
 			 * Summary returns list of valid / not valid HTML sites
 			 * 
			 * @param parser $parser The parser object to use
			 * @param string $main_url The main url (root) to behin with
			 * @return void
 			 */
 			
 			 //$url = $this->handleLink($parser, $main_url);
 			 $this->checkHeaderConsistency($parser, $main_url);
 		}
    	
    	function linkSummary(){
		    echo "<h2>Using Root URL:<u> " . BASE_URL . "</u></h2>";
		    echo "<i>Also visiting sites in the following domains: $other_servers</i>";
		    echo "<br /><br />";
		    echo "<a name = 'names'></a>";
		    echo "<h2>The following links have the same link text, but different URLS</h2>";
		    echo "<i>An example of this would be if you had two links on one of your sites, both called 'IET Services', with one pointing to a production server, and the other pointing to a development server.  From a user standpoint, 'IET Services' should go to the same place.</i>";
		    echo "<br /><a href = '#top'>Back to the top</a>";
		    
  		  	$keys = array_keys($this->link_names);
    		foreach($keys as $k){
    			$matches = explode("|||", $this->link_names[$k]);
    	   	
    			//don't display email addresses -- they are incorrectly handled
		    	if(count($matches) > 1 and validText($k, $this->ignore)){
		    		echo "<table width = '1200'>";
		    		echo "<tr><td><h3><u>$k</u></h3></td></tr>";
		    		echo "<tr><td width = '600'><b>Link Text/ URL</b></td><td width = '600'><b>Context</b> (Link to the page where this link is found)</td></tr>";
		    		echo "<ul>";
		    		foreach($matches as $m){
		    			$s = explode('CONTEXT', $m);
		    			echo "<tr><td width = '600'><li>" . $s[0] . "</li></td><td width = '600'>" . $s[1] . "</td></tr>";
		    		}
		    		echo "</ul>";
		    		echo "</table>";
		    		
		    	} //end if text is valid, display
    		} // end for each key
    
		    echo "<br />";
		    echo "<a name = 'urls'></a>";
		    echo "<h2>The following links have the same URL, but different link text</h2>";
		    echo "<i>An example of this is when you have two links on different pages of your site -- one with the text 'MyUCDavis' and the other 'Main WebPortal'.  If both of these links point to the same location, users might become confused when browsing the site.  Using the same naming conventions throughout a site provides a sense of consistency and order.</i>";
		    echo "<br /><a href = '#top'>Back to the top</a>";
		    
			$keys = array_keys($this->link_urls);
	    	foreach($keys as $k){
	    		$matches = explode("|||", $this->link_urls[$k]);
	    	
		    	//don't display email addresses -- they are incorrectly handled
		    	//if(count($matches) > 1 and !strstr($ignore, '@')){
		    	if(count($matches) > 1 and validText($k, $this->ignore)){
		    		echo "<table width = '1200'>";
		    		echo "<tr><td><h3><u>$k</u></h3></td></tr>";
		    		echo "<tr><td width = '600'><b>Link Text/ URL</b></td><td width = '600'><b>Context</b> (Link to the page where this link is found)</td></tr>";
		    		echo "<ul>";
		    		foreach($matches as $m){
		    			$s = explode('CONTEXT', $m);
		    			echo "<tr><td width = '600'><li>" . $s[0] . "</li></td><td width = '600'>" . $s[1] . "</td></tr>";
		    		}
		    		echo "</ul>";
		    		echo "</table>";
		    	} // end if text is valid, display
		    } // end for each key
	    
		    echo "<br />";
		    echo "<a name = 'missing'></a>";
		    echo "<h2>The following links were (probably) not found</h2>";
		    echo "<i>Check to see if these URLs make sense.  It is possible that the Spider has somehow constructed a bad URL, and that there shouldn't even be a page at the URL specified.</i><br />";
		    echo "<a href = '#top'>Back to the top</a><br /><br />";
		    //don't display any link with an @... it's probably an email address
		    $keys = array_keys($this->broken);
		    foreach($keys as $k){
		    	if(validText($k, $this->ignore))
		    		echo "<a href = $k>$k</a><br> ". strstr('@', $k);
		    } //end foreach key
 		}
    	
    	function checkLinkConsistency($parser, $main_url){
			/**
			 * Parses pages for <a> nodes.
			 * Summary provides a summary of:
			 * - Locations pointed to with different link 'names'
			 * - The same link 'name' pointing different places
			 * - Broken links
			 * 
			 * @param parser $parser The parser object to use
			 * @param string $main_url The main url (root) to behin with
			 * @return void
			 * 
			 */
    	
    	 	 if ($parser->iNodeType == NODE_TYPE_ELEMENT and strtolower($parser->iNodeName) == "a") {      		
	                $url = $this->handleLink($parser, $main_url);

	                //echo $url . "<br>";
	                
	                //previous element was an anchor; parse the next token and grab the text
	                $parser->parse();
	                if($parser->iNodeType == NODE_TYPE_TEXT){
	                	$text = '';
	                	
	                	while($parser->iNodeType != NODE_TYPE_ENDELEMENT){
	                		$text .= $parser->iNodeValue . ' ';
	                		$parser->parse();
	                	}
	                	
	                	if(isset($this->link_names[$text])){
	                		//add this link url to the end of the list if we haven't seen it before
	                		//strip out all slashes because they were causing problems (e.g., http://google.com SHOULD equal http://google.com/
	                		if(!strstr(str_replace('/', '', $this->link_names[$text]), str_replace('/', '', $url)))
	                			$this->link_names[$text] .= " ||| <u>$text</u> (<a href = $url>$url</a>) CONTEXT: <a href = $main_url>$main_url</a>";
	                	}
	                	else{
	                		
	                		//make sure it doesn't point to itself
	                		if($url != $main_url)
	                			$this->link_names[$text] = "<u>$text</u> (<a href = $url>$url</a>) CONTEXT: <a href = $main_url>$main_url</a>";
	                	}

	                	//Remove newlines, tabs, and some other weird characters	
	                	$text = str_replace(chr(10), "", $text);
	                	$text = str_replace(chr(11), "", $text);
	                	$text = str_replace(chr(12), "", $text);
	                	$text = str_replace(chr(13), "", $text);
	                	$text = str_replace(chr(9), "", $text);
	                	
	                	//check to see if the link text is different from known URLs (And not itself)
	                	
	                	if(isset($this->link_urls[$url])){
	                		//add this link text to the end of the list if we haven't seen it before
	                		if(!strstr(str_replace(" ", "", $this->link_urls[$url]), str_replace(" ", "", $text))){

	                			$this->link_urls[$url] .= " ||| <u>" . $text  ." </u> (<a href = $url>$url</a>) CONTEXT: <a href = $main_url>$main_url</a>";
	                		}
	                	}
	                	else{
	                		$this->link_urls[$url] = "<u>$text</u> (<a href = $url>$url</a>) CONTEXT: <a href = $main_url>$main_url</a>";	
	                	}	       			
	                } //end if text node

	        } //end if anchor
    	}
    	
    	function domainCatalogue($parser, $main_url){   	
			/**
			 * Provides a list of unique domains and the pages on which they appear
			 * 
			 * @param parser $parser The parser object to use
			 * @param string $main_url The main url (root) to behin with
			 * @return void
			 * 
			 */

	        $url = $this->handleLink($parser, $main_url);
	        
	        if ($parser->iNodeType == NODE_TYPE_ELEMENT and strtolower($parser->iNodeName) == "a") {      		
	        		$domain =  get_domain($parser->iNodeAttributes["href"]) . "<br>";
	        
	        		//if this domain isn't in the list of unique domains yet, add it
	        		//if it is, find out it's URL ID
	        		if(!isset($this->unique_domains[$domain])){
	        			$this->unique_domains[$domain]["domain"] = $domain;
	        			$this->unique_domains[$domain]["links"] = "";     				
	        		}

	        			        			
	        		$url_id = -1;	//the 'ID' of the current URL
	        			
		        	//add the "number" of the current domain to the key
	        		if(!isset($this->url_keys[$main_url])){	
	       				$url_id = count($this->url_keys);
	        			$this->url_keys[$main_url]["id"] = $url_id;
	        			$this->key_urls[$url_id] = $main_url;
	        			//echo "Using new ID $url_id<br>";
	        		}
	        		else{
	        			$url_id = $this->url_keys[$main_url]["id"];
	        			///echo "Using existing UD $url_id<br>";	
	        		}
	        		
	        		if(!strstr($this->unique_domains[$domain]["links"], "$url_id "))
	        			$this->unique_domains[$domain]["links"] .= $url_id . " ";
	        			
	        		//echo "Adding $domain for URL_ID = " . $this->url_keys[$main_url]["id"] . "<br>";
	        		
	               // "<b>Found " . get_domain($parser->iNodeAttributes["href"]) . "</b><br>";
	        } 
    	}
    	
    	function domainSummary(){
    		foreach($this->unique_domains as $domain){
    			echo "<h2>" . $domain["domain"] . "</h2>";
    			$sites = explode(" ", $domain["links"]);
    			foreach($sites as $s)
    					echo "<a href = '" . $this->key_urls[$s] . "' alt = '" . $this->key_urls[$s] . "'>$s</a> ";
    				
    			echo "<br>";	
    		}

    		echo "<br>";
    		
    		for($i = 0; $i < count($this->key_urls); $i++)
    			echo $i++ . " " . $this->key_urls[$i] . "<br>";
    		
    	}
    	
    	function siteMapRecursion($cur, $rem){
    		/**
    		 * Recursively produces a 'string' that represents an array structure for the breadcrumb
    		 * 
    		 * @param string $cur The current array
    		 * @param string $rem The remaining elements to add
    		 * @return string
    		 */
  		   		
    		$tokens = explode(":", $rem, 2);
	
    		if($tokens[0] == $rem){
    			$tokens[0] = preg_replace("/^\s*/", "", $tokens[0]);
    			$tokens[0] = preg_replace("/\s+$/", "", $tokens[0]);
    			return "['" . $tokens[0] . "']";
    		}
    		
    		//echo "Searching:(" . $tokens[0] . "<br>";
    		$tokens[0] = preg_replace("/^\s*/", "", $tokens[0]);
    		$tokens[0] = preg_replace("/\s+$/", "", $tokens[0]);
    		
    		//echo preg_match("/^\s.*/", $tokens[0]) . "<br>";
    		//echo "Searching:(" . $tokens[0] . "<br>";

    		
    		return ("['" . $tokens[0] . "']" . $this->siteMapRecursion($cur[$tokens[0]], $tokens[1]));
    	}
    	
    	function siteMapSummary(){
    		
    		$fd = fopen("./sitemap_summary.php.txt", "w");
    		if(!$fd)
				echo "Could not open file for writing";
				
			if($fd){
				fwrite($fd, '			
					
						<?php
						include("http://ietincl.ucdavis.edu/includes/head.htm");
						?>
						<title>IET : IET Services at a Glance</title>
						
						</head>
						<body> 
						<div id="page_content">
						<?php
						include("http://ietincl.ucdavis.edu/includes/navbar.htm");
						?>
						<div id="main"> 
						  <div id="main_wrapper"> 
						    <div id="breadcrumb"> <a href="/">IET Home</a>: IET Services at a Glance</div> 
						    <!-- end breadcrumb --> 
						    <h1>IET Services at a Glance</h1>
								<div id="columnwrap">
								<div id="columna" class="content_even">');
				
				fwrite($fd, '<h1>Site Map</h1>');
								fwrite($fd, "<dl>");
				
									$i = 0;
									foreach($this->catalogue as $page){
										$temp_catalogue[$page["dept"] . $i]["title"] = $page['title'];
										$temp_catalogue[$page["dept"] . $i]["url"]   = $page['url'];
										$temp_catalogue[$page["dept"] . $i]["dept"]  = $page['dept'];
										$i++;
									}
									
									//print_r($this->catalogue);
									
									//print_r($this->catalogue);
									
									ksort($temp_catalogue);
									
									$this->catalogue = $temp_catalogue;
									
									foreach($this->catalogue_sup as $page){
										if(!isset($curDept)){
											$curDept = $page['dept'];
											fwrite($fd, sprintf("<dt><br />%s</dt>", $this->divNames[$curDept]));	
										}
										else if ($curDept != $page['dept']){
											$curDept = $page['dept'];
											fwrite($fd, sprintf("<dt><br />%s</dt>", $this->divNames[$curDept]));	
										}
	
										fwrite($fd, sprintf("<dd><a href = '%s'>%s</a></dd>", $page['url'], $page['title']));									
									}
									
									
									fwrite($fd, "</dl><br /><h1>By Service Area</h1><dl>");
					
	
									foreach($this->catalogue as $page){
										if(!isset($curDept)){
											$curDept = $page['dept'];
											fwrite($fd, sprintf("<dt><br />%s</dt>", $curDept));	
										}
										else if ($curDept != $page['dept']){
											$curDept = $page['dept'];
											fwrite($fd, sprintf("<dt><br /><a href = '%s'>%s</a></dt>", $this->cataloguePages[$curDept]["url"],$curDept));	
										}
	
										fwrite($fd, sprintf("<dd><a href = '%s'>%s</a></dd>", $page['url'], $page['title']));									
									}

								fwrite($fd, "</dl>");
								
					fwrite($fd, '
								</div><!-- End columna -->
								<div id="columnb" class="content_even">

								');
			}
    		
    		
    		echo "<dl>";
    		fwrite($fd, "<dl>");
    		$this->siteMapSummaryRecursive($this->unique_domains, 0, $fd);
    		fwrite($fd, "</dl>");
    		echo "</dl>";
    		
    		if($fd){
    			fwrite($fd, '
	    			</div><!-- End columnb -->
					</div><!-- End columnwrap -->
						</div><!-- end main_wrapper --> 
					</div>
					<!-- end main --> 
					<?php
					include("http://ietincl.ucdavis.edu/includes/bottomnav.htm");
					?>
					<!-- Footer Bar --> 
					<div id="footer"> Contact: <a href="mailto:ietweb@ucdavis.edu">ietweb@ucdavis.edu</a>     Last modified: October 6, 2006     Copyright Regents of the University of California, 2006 </div> 
					<!-- end footer --> 
					<!-- End Footer Bar -->
					</div>
					</body>
					</html>'

				);
    		}
    		
    		fclose($fd);
    		
    		echo "<a href = './sitemap_summary.php.txt'>Click here</a>";
    		
    		//print_r($this->name_url_pairs);
    		echo "<br><br>";
    		print_r($this->broken);
    	}   
    	
    	
    	function siteMapSummaryRecursive($cur, $level, $fd){
    		/**
    		 * prints out the list of unique sites recursively
    		 * 
    		 * @param array $cur The current array containing the sites
    		 * @param integer $level The current level (depth) of the recursion
    		 * @param file descriptor $fd valid file descript for writing
    		 * @return void
    		 * 
    		 */
    		
	    		if(count($cur) == 0 || !is_array($cur))
	    			return;

	    		//print_r(array_keys($cur));
	    		//echo"<br>";
	    		
	    		echo "<dl>";
	    		fwrite($fd, "<dl>");
	    		foreach(array_keys($cur) as $c){
					if($c != "1"){
	    				//$this->put_spaces($level);
	    				echo "<dd><a href = '" . $this->name_url_pairs[$c] . "'>" . $c . "</a><br>";
	    				fwrite($fd, sprintf("<dd><a href = '%s'>%s</a><br>", $this->name_url_pairs[$c], $c));
					}
	    			$this->siteMapSummaryRecursive($cur[$c], $level + 1, $fd);	
	    			
	    			echo "</dd>";
	    			fwrite($fd, "</dd>");
	    		}	
	    		echo "</dl>";
	    		fwrite($fd, "</dl>");
    	}
    	
    	function put_spaces($n){
    		for($i = 0; $i < (6 * $n); $i++)
    			echo "&nbsp;";
    	}
    	
    	function brokenLinks($parser, $main_url){
    		/**
    		 * Provides a listing of broken links
    		 * 
    		 * @param parser $parser The parser object to use
    		 * @param string $main_url The main url (root) to begin with
    		 * @return void
    		 * 
    		 */
    		
    		$url = $this->handleLink($parser, $main_url);
    		
    		if(!isset($this->link_urls[$main_url])){
    			$this->link_urls[$main_url] = $url;
    		}
    		else 	
    			$this->link_urls[$main_url] .= " " . $url;
    	}
    	
    	function brokenLinksSummary(){
    		/**
    		 * 
    		 * Provides the summary for the 'broken links' action
    		 * 
    		 */
    		
    		echo "<table width = '1024'>";
    		foreach(array_keys($this->broken) as $n){
    			echo "<tr>";
    			echo "<td width = '400'>";
    			
    			echo "<a href = '$n'>" . substr($n, 0, 50) . "</a>";
    			echo "</td>";
    			echo "<td width = '124' style = 'text-align: center'>";
    			
    			echo " <b>location:</b> ";
    			echo "</td>";
    			echo "<td width = '500'>";
    			foreach(array_keys($this->link_urls) as $link){
    				if($n != '' && strstr($this->link_urls[$link], $n))
    					echo " <a href = '$link'>$link</a> ";
    				
    			}
    			echo "</td>";
    			echo "</tr>";
    			
    			//echo "<br />";
    		}
    		
    		echo "</table>";
    		echo "<br><br><br>";
    		//print_r($this->link_urls);
    	}
	               
    	function siteMap($parser, $main_url){   	
			/**
			 * Provides a site map; examines bread crumbs
			 * 
			 * @param parser $parser The parser object to use
			 * @param string $main_url The main url (root) to begin with
			 * @return void
			 * 
			 */

	        $url = $this->handleLink($parser, $main_url);
	       	       
	       $this->catalogueSite($parser, $main_url);
	        
	        if ($parser->iNodeType == NODE_TYPE_ELEMENT and strtolower($parser->iNodeName) == "div" and $parser->iNodeAttributes["id"] == "breadcrumb") {      
	        	
	        	$text = "";
	        	//while we haven't reached </div>, keep looking for text
	        	$parser->parse();
	        	while($parser->iNodeType != NODE_TYPE_ENDELEMENT or strtolower($parser->iNodeName) != "div"){
	        		$url = "";
	        		while($parser->iNodeType != NODE_TYPE_TEXT and ($parser->iNodeType != NODE_TYPE_ELEMENT or strtolower($parser->iNodeName) != "div")){
	        			if($parser->iNodeType == NODE_TYPE_ELEMENT and $parser->iNodeName = "a")
	        				$url = $parser->iNodeAttributes["href"];
	        			$parser->parse();
	        		}
	        	
	        		$text .= $parser->iNodeValue;
	        		if($url != "" and !isset($this->name_url_pairs[$text]))
	        			$this->name_url_pairs[$text] = $url;
	        		else if($url == "" and !isset($this->name_url_pairs[$text]))
	        			$this->name_url_pairs[$text] = $main_url;
	        		
	        		$parser->parse();
	        	
	        	}

	        	//add the various 'levels' to a list, preserving the structure
	        	$str = "";
	        	$str = $this->siteMapRecursion($this->unique_domains, $text);
	        	//$this->unique_domains[$str] = 1;
	        	
	        	//$str = str_replace(" ", "", $str);
	        	
	        	echo $text . "<br>";
	        	echo "<br>";
	        	
	        	$arr = "[' IET Home '][' News and Publications ']";
	        	
	        	echo "\$this->unique_domains$str<br>";

	        	//$this->unique_domains[' IET Home '][' Classrooms & Computer Rooms Services ']= 1;
	        	eval("\$this->unique_domains " . $str . "[" . count($str) . "] = 1;");
	        	//eval("\$this->unique_domains[\" IET Home \"][\" Network & Telecom \"] = 1;");
	        } 
    	} 	
    	
    	function go($action, $url, $other){
    		/**
    		 * Parses the page at $url recrusively, given bounds; applies 'function' to each page
    		 * 
    		 * @param string $action The action we wish to execute
    		 * @param string $url The base (root) URL
    		 * @param string $other Domains that are 'okay' to follow if linked to
    		 * @return void
    		 * 
    		 */
    		
    		$function = $this->getFunction($action);
    		$summary  = $this->getSummary($action);
    		
    		//by default, include the base URL in the 'other servers' array
    		$this->other_servers = $other;
    		
    		$this->checkPage($url, $function);
    		
    		//Once the above function returns, we can do the summary
    		eval($summary);
    	}
		
		function checkPage($main_url, $function){
			/**
			 * Performs specified action on the page located at: $main_url
			 * 
			 * @param string $main_url The URL of the page to visit
			 * @param string $function The function to apply (eval) to this page
			 * @return void
			 * 
			 */
			
			echo "<h2>$main_url</h2>";
			
    		set_time_limit(0);
			$startTime = gettimeofday();
    		
    		$this->debug("<b>Processing $main_url</b><br>");

    		$parser = HtmlParser_ForURL ($main_url);
	    	if($parser == null){
	    		$this->broken[$main_url] = 1;
	    	}
	    		
	    	while ($parser != null and $parser->parse()) {
	    		eval($function); 
	    		    
		    } //end while
		    
		    $current = gettimeofday();
		    //echo $main_url . " processed in " . ($current["sec"] - $startTime["sec"]) . " seconds<br>";
		    
		    //page has been parsed... parse the next one
		    //if the current page is in 'to_visit', remove it
		    if(isset($this->to_visit[$main_url]))
		    	unset($this->to_visit[$main_url]);
		    	
		    //add to visited list
		    $this->visited_links[$main_url] = 1;

		    $keys = array_keys($this->to_visit);
		    foreach($keys as $site)
		    	if(!isset($this->visited_links[$site])){    		

		    		
		    		$this->checkPage($site, $function);

		    	}
		    
	    } //end function
	    
	  
	    
	    function debug($message){
	    	/**
	    	 * Echos debug information to the screen, if $this->debug != 0
	    	 * 
	    	 * @param string $message The message to display
	    	 * @return void
	    	 * 
	    	 */
	    	
	    	if($$this->debug != 0)
	    		echo $message . "<br>";
	    	
	    }
	}
?>
